Page({
  data:{
    tle:'首页',
		subTle:'玩法介绍',
		newNotice:'',


		case:[],

		video:{}

		



  },
  onLoad(query) {

		//进入首页调用登陆接口
    this.httpRqs();

    
    
	},

	onShow(){
		this.newNotice()
		this.videoAcase()
	},


  // 去创建
  goCreatAct(){
    my.navigateTo({ url: '../activities/activities' })
  },
	caseLink(e){

		// console.info(this.data.case[e.target.dataset.index].link)
		
		// my.navigateTo({
		// 	url: '../webView/webView?url='+this.data.case[e.target.dataset.index].link
		// });

		my.qn.navigateToWebPage({
			url: this.data.case[e.target.dataset.index].link,
			success: res => {
			},
			fail: res => {
			}
    });
    

		
	},

	ggLink(e){
		// my.navigateTo({
		// 	url: '../webView/webView?url='+this.data.case[e.target.dataset.index].url
		// });

		console.info(this.data.newNotice[e.target.dataset.index].url)

		my.qn.navigateToWebPage({
			url: this.data.newNotice[e.target.dataset.index].url,
			success: res => {
			},
			fail: res => {
			}
		});

	},

	//登陆授权
	httpRqs(){

    my.authorize({
      scopes: 'scope.userInfo',
      success: (res) => {
        my.getAuthUserInfo({
          success: (userInfo) => {
            
            getApp().cloud.application.httpRequest({
              'path' : '/api/b/user/login', 
              'method':'POST',
              'headers':{ "Content-Type":"application/json"},
              'body':{avatar:userInfo.avatar,user_nick:userInfo.nickName},
              }).then(ress => {
                this.getTime();
            })

          }
        });
      },
    });

  },

 
	//获取视频 跟 case
	videoAcase(){
		getApp().cloud.application.httpRequest({
      'path' : '/api/b/user/getJson', 
      'method':'GET',
      'headers':{ "Content-Type":"application/json"},
      'body':{},
    }).then(res => {

      //console.log(res.data)

			this.setData({
				video:JSON.parse(res.data).video,
				case:JSON.parse(res.data).case
			})

			
			
    })
  },
  
	

	//获取有效时间
  getTime(){
    getApp().cloud.application.httpRequest({
      'path' : '/api/b/user/getTimeOrder', 
      'method':'GET',
      'headers':{ "Content-Type":"application/json"},
      'body':{},
    }).then(ress => {

      console.info(ress.data)

			getApp().EffectiveTime = ress.data
			
			this.header.setData({
				EffectiveTime:ress.data
			})

		
			this.newNotice()
    })
	},
	
	//通告
	newNotice(){

		getApp().cloud.application.httpRequest({
      'path' : '/api/b/getNotice', 
      'method':'GET',
      'headers':{ "Content-Type":"application/json"},
      'body':{},
    }).then(res => {
				console.info('更新公告===》',res)

				let lin = res.data;

				//处理后端返回的时间格式    
				lin.map((v,i) => {
					let time = v.createTime.substr(0,4) +'-'+v.createTime.substr(5,2)+'-'+v.createTime.substr(8,2)

					v.createTime = time
				})


				this.setData({
					newNotice:lin
				})
		})

	},

  onReady() {
		
    

  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App description',
      path: 'pages/index/index',
    };
  },
});
